﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScriptCoreLib;
using System.Windows.Media;
using ScriptCoreLib.Shared.Avalon.Extensions;

namespace AvalonTycoonMansion.Shared
{
	[Script]
	public class PropertyValueAnalytic
	{
		[Script]
		public class Quote
		{
			public int Value;
			public string Text;
			public SolidColorBrush Color;
		}


		public Quote RecentQoute;
	}

	[Script]
	public static class PropertyValueAnalyticExtensions
	{
		public static PropertyValueAnalytic.Quote GetQuote(this PropertyValueAnalytic e, int value)
		{
			if (e == null)
			{
				return new PropertyValueAnalytic.Quote
				{
					Color = Brushes.White,
					Text = value.ToDollarString(),
					Value = value
				};
			}

			if (e.RecentQoute == null)
			{
				e.RecentQoute = new PropertyValueAnalytic.Quote
				{
					Color = Brushes.Yellow,
					Text = value.ToDollarString(),
					Value = value
				};
			}
			else
			{
				if (value != e.RecentQoute.Value)
				{
					if (value > e.RecentQoute.Value)
					{
						e.RecentQoute = new PropertyValueAnalytic.Quote
						{
							Color = 0xff00ff00.ToSolidColorBrush(),
							Text = "▲ " + value.ToDollarString(),
							Value = value
						};
					}
					else
					{
						e.RecentQoute = new PropertyValueAnalytic.Quote
						{
							Color = Brushes.Red,
							Text = "▼ " + value.ToDollarString(),
							Value = value
						};
					}
				}
			}

			return e.RecentQoute;

		}
	}
}
